# 名称:Backdream
# 时间2022/12/26  20:02
# 主页页面类

from appium.webdriver.common.mobileby import MobileBy as By
from pages.base_page import BasePage

class HomePage(BasePage):
    '''定位器'''

    # 首页搜索
    search_locator = (By.ID, "com.gfeng.daydaycook:id/searchEt")

    def search_click(self):
        self.driver.find_element(*self.search_locator).click()

    # 搜索框输入
    def search_sendkeys(self, text):
        self.driver.find_element(*self.search_locator).send_keys(text)

    #进入社区...
    sqdj_locator = (By.XPATH,'//android.widget.TabWidget[@resource-id=\"android:id/tabs\"]/android.widget.RelativeLayout[2]')
    def sqdj(self):
        self.driver.find_element(*self.sqdj_locator).click()

    # 每日菜单 "翡翠饺子"
    day_food_locator = (By.XPATH,
                        "//android.support.v7.widget.RecyclerView[@resource-id=\"com.gfeng.daydaycook:id/rv_daily\"]/android.widget.LinearLayout[2]/android.widget.RelativeLayout[1]/android.widget.ImageView[1]")

    def day_food(self):
        self.driver.find_element(*self.day_food_locator).click()

    # 好物社定位
    products_locator = (By.XPATH,
                        "//android.widget.TabWidget[@resource-id=\"android:id/tabs\"]/android.widget.RelativeLayout[4]/android.widget.RelativeLayout[1]")

    # 好物社点击
    def products_click(self):
        self.find_element(self.products_locator).click()

    # 食谱分类
    food_class_locator = (By.XPATH,
                          "//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.support.v4.widget.DrawerLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.support.v7.widget.RecyclerView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[3]/android.widget.RelativeLayout[1]/android.support.v7.widget.RecyclerView[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.TextView[1]")

    def food_class(self):
        self.driver.find_element(*self.food_class_locator).click()

    # 最近活动-写菜谱0元兑换
    recent_activity_locator = (By.XPATH, "//android.widget.TextView[@text=\"写菜谱食谱0元兑换千元品质餐厨用品\"]")

    def recent_activity(self):
        self.driver.find_element(*self.recent_activity_locator).click()

    # 午餐按钮
    lunch_btn_locator = (By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/tv_lunch\"]")

    # 点击午餐
    def lunch_btn(self):
        self.driver.find_element(*self.lunch_btn_locator).click()

    # 推荐食谱文本
    food_text_father_locator = (By.XPATH,
                         "//android.support.v7.widget.RecyclerView[@resource-id=\"com.gfeng.daydaycook:id/rv_daily\"]/android.widget.LinearLayout[2]")
    food_test_son=(By.CLASS_NAME,"android.widget.TextView")


    # 早餐按钮
    breakfast_btn_locator = (By.ID, "com.gfeng.daydaycook:id/tv_breakfast")

    # 点击早餐
    def breakfast_btn(self):
        self.driver.find_element(*self.breakfast_btn_locator).click()

    # 晚餐按钮
    dinner_btn_locator = (By.XPATH,
                          "//android.support.v7.widget.RecyclerView[@resource-id=\"com.gfeng.daydaycook:id/rv_daily\"]/android.widget.LinearLayout[3]/android.widget.RelativeLayout[1]/android.widget.ImageView[1]")

    def dinner_btn(self):
        self.driver.find_element(*self.dinner_btn_locator).click()

    # 回顶部btn
    return_btn_locator = (By.XPATH,
                          "//android.widget.TabWidget[@resource-id=\"android:id/tabs\"]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]")

    def return_btn(self):
        self.driver.find_element(*self.return_btn_locator).click()

    #断言是否在主页
    assert_first_locator = (By.XPATH,"//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]"
                                     "/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.support.v4.widget.DrawerLayout[1]"
                                     "/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]"
                                     "/android.widget.RelativeLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]"
                                     "/android.support.v7.widget.RecyclerView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]"
                                     "/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]"
                                     "/android.widget.TextView[1]")
    def assert_first(self):
        return self.driver.find_element(*self.assert_first_locator).text

